package com.tarzan.edu.controller.api;

import com.tarzan.common.core.base.BaseResponse;
import com.tarzan.common.core.exception.BusinessException;
import com.tarzan.edu.entity.api.EduCourseApiResp;
import com.tarzan.edu.entity.api.IndexVO;
import com.tarzan.edu.service.IEduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Package com.tarzan.edu.controller.api
 * @Title IndexApiController
 * @Description TODO
 * @Author liujinshan
 * @CreateTime 2021/8/17 15:13
 */
@RestController
@RequestMapping("edu/api")
public class IndexApiController {

    @Autowired
    private IEduCourseService iEduCourseService;

    /**
     * @title index
     * @description TODO
     * @param 
     * @return com.tarzan.common.core.base.BaseResponse<com.tarzan.edu.entity.api.IndexVO> 
     * @author liujinshan
     * @data 2021/10/26 11:17
     */
    @GetMapping("index")
    public BaseResponse<IndexVO> index(){
        BaseResponse<IndexVO> response = new BaseResponse<>();
        try {
            response = BaseResponse.ok(iEduCourseService.index());
        } catch (BusinessException e) {
            return BaseResponse.error(e.getCode(),e.getMsg());
        } catch (Exception e){
            return BaseResponse.error("500",e.getMessage());
        }
        return response;
    }

    /**
     * @title findApiCourseById
     * @description TODO 根据id查询课程信息
     * @param id 课程id
     * @return com.tarzan.common.core.base.BaseResponse<com.tarzan.edu.entity.api.EduCourseApiResp> 
     * @author liujinshan
     * @data 2021/10/26 11:17
     */
    @GetMapping("findApiCourseById/{id}")
    public BaseResponse<EduCourseApiResp> findApiCourseById(@PathVariable String id){
        BaseResponse<EduCourseApiResp> response = new BaseResponse<>();
        try {
            response = BaseResponse.ok(iEduCourseService.findApiCourseById(id));
        } catch (BusinessException e) {
            return BaseResponse.error(e.getCode(),e.getMsg());
        } catch (Exception e){
            return BaseResponse.error("500",e.getMessage());
        }
        return response;
    }

}
